Getting the Data
Tech stack
The data was collected with the following technologies:
-
Satellite images: The satellite images were obtained through
Sentinelhub
which gives access to a number of satellites includingHarmonized Landsat Sentinel
which was used for this project.Satellite images were collected for 3 different time periods (for the 3 months in a season) and 6 bands (blue, green, red, NIR_Narrow, SWIR1, SWIR2) for each region.
-
Saving images:
Osgeo GDAL
was used to save the images to a geotiff file in the proper format that can be analyzed by the computer vision model. -
Geospatial data: The geospatial data of the exact latitude/longitude and address of the selected region was obtained through the
Nominatim API
.
Code snippets
Getting geospatial data
const fetchCoords = (district: string) => {
const url = "https://nominatim.openstreetmap.org/search?q=" + district + "&format=json";
fetch(url)
.then(response => response.json())
.then(data => {
setPlaces(data);
})
}
const fetchCity = (lat: any, lng: any) => {
fetch(`https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lng}&zoom=6&format=json`)
.then(response => response.json())
.then((data: any) => {
setName(data["display_name"]);
if (name !== "Empty") {
fetchCoords(data["display_name"]);
}
setMessage("");
setError("");
})
}
Getting satellite images
def get_data(glacier_bbox, time_interval, evalscript):
"""
glacier_bbox is the bounding coordinates of the region
time_interval is the time interval for the satellite image
evalscript is a script telling which band of wavelength (blue, green, infrared, etc) to return
"""
request = SentinelHubRequest(
evalscript=evalscript,
input_data=[
SentinelHubRequest.input_data(
data_collection=DataCollection.HARMONIZED_LANDSAT_SENTINEL,
time_interval=time_interval,
)
],
responses=[SentinelHubRequest.output_response("default", MimeType.PNG)],
bbox=glacier_bbox,
size=glacier_size,
config=config,
)
return request.get_data()[0]
Saving the images
def write_geotiff(filename, arrays, extent):
def getGeoTransform(extent, nlines, ncols):
resx = (extent[2] - extent[0]) / ncols
resy = (extent[3] - extent[1]) / nlines
return [extent[0], resx, 0, extent[3] , 0, -resy]
arr_type = gdal.GDT_Int16
driver = gdal.GetDriverByName("GTiff")
out_ds = driver.Create(filename, arrays[0].shape[1], arrays[0].shape[0], 18, arr_type)
srs = osr.SpatialReference()
out_ds.SetProjection(srs.ExportToWkt())
out_ds.SetGeoTransform(getGeoTransform(extent, arrays[0].shape[0], arrays[0].shape[1]))
for i, arr in enumerate(arrays, 1):
band = out_ds.GetRasterBand(i)
band.WriteArray(arr)
band.FlushCache()